#define DEBUG
#include <cstdio>

using namespace std;

const int maxn = 500000;

int read() {
  char c;
  for (c=getchar(); c<'0' || c>'9'; c=getchar());
  int ret=0;
  for (; c>='0' && c<='9'; c=getchar()) {
    ret = ret*10+c-'0';
  }
  return ret;
}

int solve(int k, int l1, int r1, int a[], int l2, int r2, int b[]) {
  if (l1>r1) {
    return b[l2+k-1];
  } else if (l2>r2) {
    return a[l1+k-1];
  } else {
    int mid1=(l1+r1)/2, mid2=(l2+r2)/2;
    if (a[mid1]<b[mid2]) {
      if (mid1-l1+mid2-l2+1>=k) {
	return solve(k, l1, r1, a, l2, mid2-1, b);
      } else {
	return solve(k-mid1+l1-1, mid1+1, r1, a, l2, r2, b);
      }
    } else {
      if (mid2-l2+mid1-l1+1>=k) {
	return solve(k, l1, mid1-1, a, l2, r2, b);
      } else {
	return solve(k-mid2+l2-1, l1, r1, a, mid2+1, r2, b);
      }
    }
  }
}

int main() {
  freopen("median.in", "r", stdin);
  freopen("median.out", "w", stdout);

  static int a[maxn+1], b[maxn+1];
  int n=read(), m=read();
  for (int i=1; i<=n; i++) {
    a[i]=read();
  }
  for (int i=1; i<=n; i++) {
    b[i]=read();
  }

  for (int i=1; i<=m; i++) {
    int opt=read();
    if (opt==1) {
      int x=read(), y=read(), z=read();
      if (x) {
	b[y] = z;
      } else {
	a[y] = z;
      }
    } else {
      int l1=read(), r1=read(), l2=read(), r2=read();
      printf("%d\n", solve((r1-l1+1+r2-l2+1)/2+1, l1, r1, a, l2, r2, b));
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
